//
//  NewsHeaderView.m
//  ZYHome
//
//  Created by Teplot_03 on 16/7/6.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "NewsHeaderView.h"

@interface NewsHeaderView ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *titleTF;



@property (nonatomic, strong) UIView *topLine;

@property (nonatomic, strong) UIView *bottomLine;

@property (nonatomic, strong) UIView *bottomLine2;

@end

@implementation NewsHeaderView

@synthesize text = _text;

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    [self addSubview:self.titleTF];
    [self addSubview:self.button];
    [self addSubview:self.topLine];
    [self addSubview:self.bottomLine];
    [self addSubview:self.bottomLine2];
    
    [_topLine mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(0),
        make.left.mas_equalTo(0),
        make.width.mas_equalTo(KScreenWidth),
        make.height.mas_equalTo(0.5);
    }];
    
    [_titleTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(_topLine.mas_bottom).offset(0),
        make.left.mas_equalTo(20),
        make.width.mas_equalTo(KScreenWidth-40),
        make.height.mas_equalTo(40);
    }];
    
    [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(_titleTF.mas_bottom).offset(0),
        make.left.mas_equalTo(0),
        make.width.mas_equalTo(KScreenWidth),
        make.height.mas_equalTo(0.5);
    }];
    
    [_button mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(_bottomLine.mas_bottom).offset(0),
        make.left.mas_equalTo(20),
        make.width.mas_equalTo(KScreenWidth-40),
        make.height.mas_equalTo(40);
    }];
    
    [_bottomLine2 mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(_button.mas_bottom).offset(0),
        make.left.mas_equalTo(0),
        make.width.mas_equalTo(KScreenWidth),
        make.height.mas_equalTo(0.5);
    }];
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if ([self.delegate respondsToSelector:@selector(newsHeaderViewdidEndEditing:)]) {
        [self.delegate newsHeaderViewdidEndEditing:self];
    }
}

- (UITextField *)titleTF {
    if (!_titleTF) {
        _titleTF = [[UITextField alloc] init];
        _titleTF.placeholder = @"标题";
        _titleTF.textColor = grayTextColor;
        _titleTF.delegate = self;
        _titleTF.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _titleTF;
}

- (UIView *)topLine {
    if (!_topLine) {
        _topLine = [UIView new];
        _topLine.backgroundColor = LightGray_Color;
    }
    return _topLine;
}

- (UIView *)bottomLine {
    if (!_bottomLine) {
        _bottomLine = [UIView new];
        _bottomLine.backgroundColor = LightGray_Color;
    }
    return _bottomLine;
}
- (UIButton *)button {
    if (!_button) {
        _button = [UIButton new];
        [self.button setTitle:@"点击选择活动" forState:UIControlStateNormal];
        [self.button setTitleColor:Theme_Color forState:UIControlStateNormal];
    }
    return _button;
}

- (UIView *)bottomLine2 {
    if (!_bottomLine2) {
        _bottomLine2 = [UIView new];
        _bottomLine2.backgroundColor = LightGray_Color;
    }
    return _bottomLine2;
}
#pragma mark - **************** getter
- (NSString *)text {
    return self.titleTF.text;
}

- (void)endInput {
    [self.titleTF resignFirstResponder];
}

- (void)setText:(NSString *)text {
    _text = text;
    _titleTF.text = text;
}

@end
